package beans;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map.Entry;
import org.hibernate.*;
import domain.DeliveryOrder;
/**
 * DeliveryOrderQuery 
 */
public class DeliveryOrderQuery extends AbstractPagedQuery<DeliveryOrder> {
	/**
	 * 订单编号 
	 */
	private String orderNumber;
	/**
	 * 订单类型 
	 */
	private String orderType;
	/**
	 * VIP订单 
	 */
	private String vipCustomFlag;
	/**
	 * 寄件人 
	 */
	private String sender;
	/**
	 * 收件人 
	 */
	private String receiver;
	/**
	 * 始发地 
	 */
	private String originLocation;
	/**
	 * 目的地 
	 */
	private String destLocation;
	/**
	 * 付款类型 
	 */
	private String payType;
	/**
	 * 订单日期 
	 */
	private Timestamp orderDate;
	/**
	 * 货物品名 
	 */
	private String goodsName;
	/**
	 * 服务类型 
	 */
	private String serviceType;
	/**
	 * 分站点 
	 */
	private String subStation;
	/**
	 * 录入 
	 */
	private String creater;
	/**
	 * 取件 
	 */
	private String fetcher;
	/**
	 * 派送 
	 */
	private String dispatcher;
	/**
	 * 状态 
	 */
	private String orderStatus;
	/**
	 * 调度 
	 */
	private String scheduler;
	/**
	 * 构建hibernate Query对象.需要构造查询sql语句,并将查询参数设置到Query对象中.
	 * @param pSession hibernate session
	 * @param pIsQueryTotalCount 是否是构造查询纪录总数目的Query.
	 * @return hibernate Query
	 */
	public Query buildQuery(Session pSession, boolean pIsQueryTotalCount) {
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		if (pIsQueryTotalCount) {// 查询总数
		    sql.append("select count(*) from DeliveryOrder t where 1=1 ");
		} else {
	    	sql.append(" from DeliveryOrder t where 1=1 ");
	    }
	    	if (null != orderNumber) {
	        queryParams.put("orderNumber", "%"+orderNumber+"%");
	        sql.append(" and t.orderNumber like:orderNumber ");
	    }
	    	if (null != orderType) {
	        queryParams.put("orderType", "%"+orderType+"%");
	        sql.append(" and t.orderType like:orderType ");
	    }
	    	if (null != vipCustomFlag) {
	        queryParams.put("vipCustomFlag", "%"+vipCustomFlag+"%");
	        sql.append(" and t.vipCustomFlag like:vipCustomFlag ");
	    }
	    	if (null != sender) {
	        queryParams.put("sender", "%"+sender+"%");
	        sql.append(" and t.sender like:sender ");
	    }
	    	if (null != receiver) {
	        queryParams.put("receiver", "%"+receiver+"%");
	        sql.append(" and t.receiver like:receiver ");
	    }
	    	if (null != originLocation) {
	        queryParams.put("originLocation", "%"+originLocation+"%");
	        sql.append(" and t.originLocation like:originLocation ");
	    }
	    	if (null != destLocation) {
	        queryParams.put("destLocation", "%"+destLocation+"%");
	        sql.append(" and t.destLocation like:destLocation ");
	    }
	    	if (null != payType) {
	        queryParams.put("payType", "%"+payType+"%");
	        sql.append(" and t.payType like:payType ");
	    }
	    	if (null != orderDate) {
	        queryParams.put("orderDate", orderDate);
			sql.append(" and t.orderDate =:orderDate ");
	    }
	    	if (null != goodsName) {
	        queryParams.put("goodsName", "%"+goodsName+"%");
	        sql.append(" and t.goodsName like:goodsName ");
	    }
	    	if (null != serviceType) {
	        queryParams.put("serviceType", "%"+serviceType+"%");
	        sql.append(" and t.serviceType like:serviceType ");
	    }
	    	if (null != subStation) {
	        queryParams.put("subStation", "%"+subStation+"%");
	        sql.append(" and t.subStation like:subStation ");
	    }
	    	if (null != creater) {
	        queryParams.put("creater", "%"+creater+"%");
	        sql.append(" and t.creater like:creater ");
	    }
	    	if (null != fetcher) {
	        queryParams.put("fetcher", "%"+fetcher+"%");
	        sql.append(" and t.fetcher like:fetcher ");
	    }
	    	if (null != dispatcher) {
	        queryParams.put("dispatcher", "%"+dispatcher+"%");
	        sql.append(" and t.dispatcher like:dispatcher ");
	    }
	    	if (null != orderStatus) {
	        queryParams.put("orderStatus", "%"+orderStatus+"%");
	        sql.append(" and t.orderStatus like:orderStatus ");
	    }
	    	if (null != scheduler) {
	        queryParams.put("scheduler", "%"+scheduler+"%");
	        sql.append(" and t.scheduler like:scheduler ");
	    }
	    Query query = pSession.createQuery(sql.toString());
	    for (Entry<String, Object> entry : queryParams.entrySet()) {
	        query.setParameter(entry.getKey(), queryParams.get(entry.getKey()));
	    }
	    return query;
	}
	/**
	 * @return String 
	 */
	public String getOrderNumber(){
		return orderNumber;
	}
	/**
	 * @param pOrderNumber 
	 */
	public void setOrderNumber(String pOrderNumber){
		orderNumber=pOrderNumber;
	}
	/**
	 * @return String 
	 */
	public String getOrderType(){
		return orderType;
	}
	/**
	 * @param pOrderType 
	 */
	public void setOrderType(String pOrderType){
		orderType=pOrderType;
	}
	/**
	 * @return String 
	 */
	public String getVipCustomFlag(){
		return vipCustomFlag;
	}
	/**
	 * @param pVipCustomFlag 
	 */
	public void setVipCustomFlag(String pVipCustomFlag){
		vipCustomFlag=pVipCustomFlag;
	}
	/**
	 * @return String 
	 */
	public String getSender(){
		return sender;
	}
	/**
	 * @param pSender 
	 */
	public void setSender(String pSender){
		sender=pSender;
	}
	/**
	 * @return String 
	 */
	public String getReceiver(){
		return receiver;
	}
	/**
	 * @param pReceiver 
	 */
	public void setReceiver(String pReceiver){
		receiver=pReceiver;
	}
	/**
	 * @return String 
	 */
	public String getOriginLocation(){
		return originLocation;
	}
	/**
	 * @param pOriginLocation 
	 */
	public void setOriginLocation(String pOriginLocation){
		originLocation=pOriginLocation;
	}
	/**
	 * @return String 
	 */
	public String getDestLocation(){
		return destLocation;
	}
	/**
	 * @param pDestLocation 
	 */
	public void setDestLocation(String pDestLocation){
		destLocation=pDestLocation;
	}
	/**
	 * @return String 
	 */
	public String getPayType(){
		return payType;
	}
	/**
	 * @param pPayType 
	 */
	public void setPayType(String pPayType){
		payType=pPayType;
	}
	/**
	 * @return Timestamp 
	 */
	public Timestamp getOrderDate(){
		return orderDate;
	}
	/**
	 * @param pOrderDate 
	 */
	public void setOrderDate(Timestamp pOrderDate){
		orderDate=pOrderDate;
	}
	/**
	 * @return String 
	 */
	public String getGoodsName(){
		return goodsName;
	}
	/**
	 * @param pGoodsName 
	 */
	public void setGoodsName(String pGoodsName){
		goodsName=pGoodsName;
	}
	/**
	 * @return String 
	 */
	public String getServiceType(){
		return serviceType;
	}
	/**
	 * @param pServiceType 
	 */
	public void setServiceType(String pServiceType){
		serviceType=pServiceType;
	}
	/**
	 * @return String 
	 */
	public String getSubStation(){
		return subStation;
	}
	/**
	 * @param pSubStation 
	 */
	public void setSubStation(String pSubStation){
		subStation=pSubStation;
	}
	/**
	 * @return String 
	 */
	public String getCreater(){
		return creater;
	}
	/**
	 * @param pCreater 
	 */
	public void setCreater(String pCreater){
		creater=pCreater;
	}
	/**
	 * @return String 
	 */
	public String getFetcher(){
		return fetcher;
	}
	/**
	 * @param pFetcher 
	 */
	public void setFetcher(String pFetcher){
		fetcher=pFetcher;
	}
	/**
	 * @return String 
	 */
	public String getDispatcher(){
		return dispatcher;
	}
	/**
	 * @param pDispatcher 
	 */
	public void setDispatcher(String pDispatcher){
		dispatcher=pDispatcher;
	}
	/**
	 * @return String 
	 */
	public String getOrderStatus(){
		return orderStatus;
	}
	/**
	 * @param pOrderStatus 
	 */
	public void setOrderStatus(String pOrderStatus){
		orderStatus=pOrderStatus;
	}
	/**
	 * @return String 
	 */
	public String getScheduler(){
		return scheduler;
	}
	/**
	 * @param pScheduler 
	 */
	public void setScheduler(String pScheduler){
		scheduler=pScheduler;
	}
}
